#ifndef _CONFIG_H_
#define _CONFIG_H_

#include <vector>
#include <string>
#include "SimpleIni.h"

#ifdef _UNICODE
typedef wchar_t SI_CHAR;
typedef std::wstring string_t;
#else 
typedef char SI_CHAR;
typedef std::string string_t;
#endif

//namespace pktoon
// {
	
	class Config
	{
	public:
		Config(const SI_CHAR* filePath);
		~Config();
	public:
		template<class type> type Get(const SI_CHAR* section, const SI_CHAR* key, type def) const;
		template<class type> void Set(const SI_CHAR* section, const SI_CHAR* key, type def) ;
		void GetAllSec(std::vector<string_t>& secs);
		void GetAllKey(const SI_CHAR* section, std::vector<string_t>& keys);
		const SI_CHAR* GetString(const SI_CHAR* section, const SI_CHAR* key, const SI_CHAR* def = _T("")) const;
		template<> string_t Get<string_t>(const SI_CHAR* section, const SI_CHAR* key, string_t def) const {return GetString(section, key, def.c_str()); }

		int GetInt(const SI_CHAR* section, const SI_CHAR* key, int def = 0) const;
		template<> int Get<int>(const SI_CHAR* section, const SI_CHAR* key, int def) const {return GetInt(section, key, def);}
		//template<> const SI_CHAR* Get<const SI_CHAR*>(const SI_CHAR* section, const SI_CHAR* key, const SI_CHAR* def) const {return GetString(section, key, def);}

		bool GetBool(const SI_CHAR* section, const SI_CHAR* key, bool def = true) const;
		template<> bool Get<bool>(const SI_CHAR* section, const SI_CHAR* key, bool def) const {return GetBool(section, key, def);}

		float GetFloat(const SI_CHAR* section, const SI_CHAR* key, float def = 0.0f) const;

		void SetString(const SI_CHAR* section, const SI_CHAR* key, const SI_CHAR* value);
		template<> void Set<string_t>(const SI_CHAR* section, const SI_CHAR* key, string_t def) { return SetString(section, key, def.c_str());}

		//template<> void Set<const SI_CHAR*>(const SI_CHAR* section, const SI_CHAR* key, const SI_CHAR* value) { return SetString(section, key, value);}


		void SetInt(const SI_CHAR* section, const SI_CHAR* key, int value);
		template<> void Set<int>(const SI_CHAR* section, const SI_CHAR* key, int value) { return SetInt(section, key, value);}

		void SetBool(const SI_CHAR* section, const SI_CHAR* key, bool value);
		template<> void Set<bool>(const SI_CHAR* section, const SI_CHAR* key, bool value) { return SetBool(section, key, value);}

		void SetFloat(const SI_CHAR* section, const SI_CHAR* key, float value);


		void Flush();
	protected:
		CSimpleIni m_ini;
		string_t m_filePath;
		bool m_modified;
	};
/*}*/
#endif
